
package com.zsrt.day20170417.ch03;

import org.junit.Test;

import com.zsrt.utils.ArrayUtil;

public class PetDaoTest {
	
	
	PetDao dao = new PetDaoImpl();
	@Test
	public void addPetTest() throws Exception {
		
		
		/*PetShop shop = new PetShop();
		shop.setShopName("华润商店");
		
		
		//1.set 初始化笼子的代码
		Pet[] pets2 = new Pet[5];
		shop.setPets(pets2);*/
		
		//2.构造方法
		Pet[] pets = new Pet[5];
		PetShop shop = new PetShop("huarun", pets );
		
		
		
		
		Cat cat = new Cat("黑猫警长");
		
		Dog dog = new Dog("忠犬八公");
		
		
		boolean b = dao.addPet(shop, cat);
		boolean a = dao.addPet(shop, dog);
		System.out.println(b);
		System.out.println(a);
		
		
		Pet[] pets2=shop.getPets();
		ArrayUtil.StudentEntity(pets2);
		
		Pet pet = dao.findPetByName(shop, "忠犬八公");
		System.out.println(pet);
		
		
		Cat duo = new Cat("多啦", 2);
		dao.addPet(shop, duo);
		Dog ah = new Dog("阿黄",2);
		dao.addPet(shop, ah);
		
		dao.findPetsByAge(shop, 2);
		Pet[] pets3=shop.getPets();
		ArrayUtil.StudentEntity(pets3);
		
		
	}
	@Test
	public void updateTest() throws Exception {
		
		Cat cat = new Cat("黑猫警长",2,"紫色");
		
		Dog dog = new Dog("忠犬八公",4,"土黄色");
		Pet[] pets3 = new Pet[10];
		
		pets3[0] =cat;
		pets3[1] =dog;
		PetShop huarun = new PetShop("华润", pets3 );
		
		Pet condition = new Cat( "黑猫警长",4,"黄色");
		Pet pet = dao.updateByConditions(huarun, condition);
		System.out.println(pet);
	}
	
	/**
	 * 随意改变条件都能找出符合要求的宠物数组
	 */
	@Test
	public void updatePetsByConditionsTest() throws Exception {
		
		Cat cat = new Cat("黑猫警长",2,"紫色");
		Cat c = new Cat("芭比",2,"黄色");
		
		Pet[] pets3 = new Pet[10];
		Dog dog = new Dog("忠犬八公",4,"土黄色");
		Dog xiao = new Dog("小强",2,"黄色");
		
		pets3[0] =cat;
		pets3[1] =dog;
		pets3[2] =c;
		pets3[3] =xiao;
		
		PetShop huarun = new PetShop("华润", pets3 );
		
		Pet condition = new Cat(2,"黄色");
		
		Pet alterPets = new Dog(3, "七彩");
		Pet[] pets = dao.updatePetsByConditions(huarun, condition, alterPets );
		ArrayUtil.StudentEntity(pets);
	}
}
